//
//  UUAlertViewController.h
//  UUZuche
//
//  Created by phenmod on 14-10-16.
//
//

/*
 正常需要AlertViewController的时候使用本层代码。
 参考自：https://github.com/i-dama/IDAlertController

 本类目的:  兼容AlertView和UIAlertViewController
           提供可以创建一个单例对话框的函数
           统一管理全局的对话框？

 TODO:  现在使用的IDAlertController并未处理alertView的textFiled
        如果alertView的可点button数量过多，iOS8显示会超过屏幕，不能滑动，待处理
        UIAlertVIew中message过长的情况下，布局崩溃（iOS7允许内容滑动）。
        未来关注下各种AlertController，并更新本类
 */

#import <Foundation/Foundation.h>
#import "UUAlertAction.h"
#import <UIKit/UIKit.h>

typedef NS_ENUM(NSUInteger, UUAlertControllerStyle)
{
    UUAlertControllerStyleActionSheet = 0,
    UUAlertControllerStyleAlert
};

typedef void (^UUAlertControllerTextFieldConfigurationHandler)(UITextField *textField);


@interface JNAlertController : NSObject

// =================================================================================================
#pragma mark - Utility
// =================================================================================================

// 创建单例AlertView
// TODO: 未测试
- (id)initSingleAlertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UUAlertControllerStyle)preferredStyle
                                 actions:(NSArray *)actions;

// 常用单按钮AlertView
+ (instancetype)alertOneActionWithTitle:(NSString *)title
                                message:(NSString *)message
                            actionTitle:(NSString *)actionTitle
                                 action:(UUAlertActionHandlerBlock)actionHandler;

// 常用双按钮AlertView，左侧取消无动作，右侧有动作
+ (instancetype)alertTwoActionsWithTitle:(NSString *)title
                                 message:(NSString *)message
                             cancelTitle:(NSString *)cancelTitle
                             actionTitle:(NSString *)actionTitle
                                  action:(UUAlertActionHandlerBlock)actionHandler;

// 常用双按钮AlertView，左侧取消有动作，右侧有动作
+ (instancetype)alertTwoActionsWithTitle:(NSString *)title
                                 message:(NSString *)message
                             cancelTitle:(NSString *)cancelTitle
                            cancelAction:(UUAlertActionHandlerBlock)cancelActionHandler
                             actionTitle:(NSString *)actionTitle
                                  action:(UUAlertActionHandlerBlock)actionHandler;

// =================================================================================================
#pragma mark - 实现
// =================================================================================================

+ (instancetype)alertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UUAlertControllerStyle)preferredStyle;
+ (instancetype)alertControllerWithTitle:(NSString *)title
                                 message:(NSString *)message
                          preferredStyle:(UUAlertControllerStyle)preferredStyle
                                 actions:(NSArray *)actions;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *message;
@property (nonatomic, readonly) UUAlertControllerStyle preferredStyle;

// actions
- (void)addAction:(UUAlertAction *)action;
- (void)addActionWithTitle:(NSString *)title
                     style:(UUAlertActionStyle)style
                   handler:(UUAlertActionHandlerBlock)handler;
@property (nonatomic, readonly) NSArray *actions;

// 默认从最前面的页面弹出
- (void)show;
// 在某些页面，比如连连支付页面，从这些页面返回后，这些第三方SDK会把弹出它们的页面之上的页面（包括它们自己）都清空。直接在
// topViewController 弹出，会把本AlertController都清空。所以，必须带一个指定参数，从哪个页面弹出。
- (void)showInViewController:(UIViewController *)viewController;
- (void)showInViewController:(UIViewController *)viewController
                  completion:(void (^)(void))completion;

- (void)dismiss;
@end
